package com.sl.core.engine.datasource;

import org.anyline.data.transaction.TransactionDefine;
import org.anyline.data.transaction.TransactionState;
import org.anyline.data.transaction.init.DefaultTransactionManage;

import javax.sql.DataSource;
import java.sql.SQLException;

public class ProcessTransactionManage extends DefaultTransactionManage {


    private String key;

    public ProcessTransactionManage(String key, DataSource datasource) {
        super(datasource);
        this.key = key;
    }

    @Override
    public TransactionState start(TransactionDefine define) throws SQLException {
        TransactionState start = super.start(define);
        ProcessConnectionHolder.set(this.key, start.getConnection());
        return start;
    }

    @Override
    public void commit(TransactionState state) throws SQLException {
        super.commit(state);
        ProcessConnectionHolder.remove(this.key);
    }

    @Override
    public void rollback(TransactionState state) throws SQLException {
        super.rollback(state);
        ProcessConnectionHolder.remove(this.key);
    }
}
